package com.kc.zhaojiu.controller;

import com.kc.zhaojiu.service.ex.CompanyInfoNotFoundException;
import com.kc.zhaojiu.service.ex.ServiceException;
import com.kc.zhaojiu.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * Author: QiongKe~
 * Date: 2022/10/7 21:25
 */
public class BaseController {
    /** 操作成功的状态码 */
    public static final int OK = 200;
    /** @ExceptionHandler用于统一处理方法抛出的异常 */

    @ExceptionHandler({ServiceException.class,NullPointerException.class})
    public JsonResult<Void> handleException(Throwable e) {
        JsonResult<Void> result = new JsonResult<>(e);
        if (e instanceof CompanyInfoNotFoundException) {
            result.setCode(6000);
        }else if(e instanceof NullPointerException){
            result.setCode(500);
            result.setMessage("空指针异常！！！");
        }
        return result;
    }

}
